{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Simple Linear Regression\n",
    "\n",
    "In this example, we illustrate how to solve a linear regression problem.\n",
    "Suppose we have training data, can we fit a neural network on it? The trained neural network (an MLP) is then validated on the test split.\n",
    "\n",
    "Let's load the python packages first."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import absolute_import\n",
    "from __future__ import division\n",
    "from __future__ import print_function\n",
    "\n",
    "# numpy package\n",
    "import numpy as np\n",
    "# for plotting\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# keras modules\n",
    "from tensorflow.keras.models import Sequential\n",
    "from tensorflow.keras.layers import Dense\n",
    "from tensorflow.keras.utils import plot_model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Generate Artificial Data\n",
    "\n",
    "Assuming we have 1D input and 1D output, let us generate the train data assuminng the underlying function is a polynomial:\n",
    "\\begin{align}\n",
    "y= f(x) = x^2 - 2x + 1   \n",
    "\\end{align}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f95720c3450>]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAd+0lEQVR4nO3db2xc13km8OchJTmlFMQtxW60tkQ2iJHWLhrHJbxOvSgCSx8cN7C7iIM6uFLk1AEjsUGYbYHCAQEDNUDsej8kKzcZqrStVLIGibtOkCqBgyBSbKQtaiW0azlW1KSqIcaCjZ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fHVyXIXkjXBxbiP9T2fD7+QiAM2b2hYhm6X02WV8FTnCV+H/A/Q/2FoD/APBd//X/CuCJpivFP4MbyU5m3e+IcxkEcALAv/n3v+G/PgrgYf/xHwD4MVzWxY8B3JN1v5vOYc3fM4D7AdzuP34HgP8H4CyAHwJ4T9Z97uBc/heA0/5n8SSA3866zzHn8lUArwC46P97uQfAPgD7/OME8GX/XH+MiIyxPNwSnMtnGj6XpwH8QdZ9jjmX/w43ffI8gOf8223d+my09F9EpCTKMuUiIlJ5CugiIiWhgC4iUhIK6CIiJaGALiJSEgroIiIloYAuIlIS/x9JIWGsXowIWgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# generate train x data\n",
    "x_train = np.random.uniform(low=-1.0, high=2.0, size=[200,1])\n",
    "# generate train y data\n",
    "y_train = x_train*x_train - 2*x_train + 1\n",
    "\n",
    "plt.figure()\n",
    "plt.plot(x_train, y_train, 'bo')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then, let us generate the test data and plot the train and test data together. Note that the test data is beyond the [-1,2] range of `x_train`. This will enable us to verify if our model can generalize (ie make prediction from never seen before data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAU5klEQVR4nO3df2zcd33H8dfbNql/JB4szerQUjudJkQLRQxrKoMRhiPRMQQb6zrI16EtQ25i2LqJbYCqjilRtD82oVVazqkFZaU+AVNJtWlj/EigVJGWCqd0LCG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S7/yjtOlLwW5J+4u5j7n5J0pckvS/lmqrO3R+X9Iu060iTu4+7+5MLX5+XdEp59mptFMEF9QoflvRfaReBqkm0kTIai5n1SHqTpCfSrSQ9iTYOKDczOyzl3Y3zXnf/t4Vj7lX89idbzdqqJclr0IASbaSMxmFmGyV9RdJfuPuLadeTllSC2t13FLvfzO6Q9B5JfV6nE71LvQYNio2UcZmZvUJxSGfd/VDa9aQpuNaHmd0q6ROS3uvu02nXg6r6rqTfMLNtZrZB0gck/XvKNSEFZmaSPifplLt/Ju160hZcUEv6Z0mbJH3TzJ4ys4NpF1RtZvaHZvaspLdI+k8z+3raNVXDwknk3EbKpyT9ayNupGxmX5T035Jea2bPmtmfpl1TCt4qaZekdy7kwFNm9u60i0oLl5ADQOBCHFEDAJYgqAEgcAQ1AASOoAaAwBHUABA4ghoAAkdQA0Dg/h/EI5CxAzAmwAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# generate test x data\n",
    "x_test = np.random.uniform(low=-2.0, high=3.0, size=[20,1])\n",
    "# generate test y data\n",
    "y_test = x_test*x_test - 2*x_test + 1\n",
    "\n",
    "plt.plot(x_train, y_train, 'bo', x_test, y_test, 'r*')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3-layer MLP Model\n",
    "\n",
    "Then, let us build a 3-layer 64-128-1 MLP."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"linear_regressor\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_layer (Dense)          (None, 64)                128       \n",
      "_________________________________________________________________\n",
      "hidden_layer (Dense)         (None, 128)               8320      \n",
      "_________________________________________________________________\n",
      "output_layer (Dense)         (None, 1)                 129       \n",
      "=================================================================\n",
      "Total params: 8,577\n",
      "Trainable params: 8,577\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n",
      "Epoch 1/100\n",
      "50/50 [==============================] - 0s 3ms/step - loss: 1.0276 - val_loss: 4.9706\n",
      "Epoch 2/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.1931 - val_loss: 2.7254\n",
      "Epoch 3/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0804 - val_loss: 2.2440\n",
      "Epoch 4/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0575 - val_loss: 1.8591\n",
      "Epoch 5/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0475 - val_loss: 1.6330\n",
      "Epoch 6/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0409 - val_loss: 1.5586\n",
      "Epoch 7/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0375 - val_loss: 1.4400\n",
      "Epoch 8/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0333 - val_loss: 1.4230\n",
      "Epoch 9/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0307 - val_loss: 1.3709\n",
      "Epoch 10/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0289 - val_loss: 1.2765\n",
      "Epoch 11/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0266 - val_loss: 1.3010\n",
      "Epoch 12/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0244 - val_loss: 1.2236\n",
      "Epoch 13/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0235 - val_loss: 1.2113\n",
      "Epoch 14/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0214 - val_loss: 1.2156\n",
      "Epoch 15/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0196 - val_loss: 1.1431\n",
      "Epoch 16/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0186 - val_loss: 1.1463\n",
      "Epoch 17/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0171 - val_loss: 1.1123\n",
      "Epoch 18/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0156 - val_loss: 1.0624\n",
      "Epoch 19/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0146 - val_loss: 1.0403\n",
      "Epoch 20/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0138 - val_loss: 1.0194\n",
      "Epoch 21/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0130 - val_loss: 0.9956\n",
      "Epoch 22/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0110 - val_loss: 0.9711\n",
      "Epoch 23/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0113 - val_loss: 0.9489\n",
      "Epoch 24/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0103 - val_loss: 0.9598\n",
      "Epoch 25/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0097 - val_loss: 0.9324\n",
      "Epoch 26/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0089 - val_loss: 0.9162\n",
      "Epoch 27/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0084 - val_loss: 0.9133\n",
      "Epoch 28/100\n",
      "50/50 [==============================] - 0s 2ms/step - loss: 0.0079 - val_loss: 0.9003\n",
      "Epoch 29/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0072 - val_loss: 0.9243\n",
      "Epoch 30/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0070 - val_loss: 0.8808\n",
      "Epoch 31/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0064 - val_loss: 0.8721\n",
      "Epoch 32/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0061 - val_loss: 0.8552\n",
      "Epoch 33/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0057 - val_loss: 0.8433\n",
      "Epoch 34/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0053 - val_loss: 0.8256\n",
      "Epoch 35/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0051 - val_loss: 0.8175\n",
      "Epoch 36/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0047 - val_loss: 0.7790\n",
      "Epoch 37/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0046 - val_loss: 0.7914\n",
      "Epoch 38/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0044 - val_loss: 0.7798\n",
      "Epoch 39/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0041 - val_loss: 0.7754\n",
      "Epoch 40/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0040 - val_loss: 0.7534\n",
      "Epoch 41/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0038 - val_loss: 0.7344\n",
      "Epoch 42/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0035 - val_loss: 0.7535\n",
      "Epoch 43/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0033 - val_loss: 0.7402\n",
      "Epoch 44/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0032 - val_loss: 0.7357\n",
      "Epoch 45/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0032 - val_loss: 0.7198\n",
      "Epoch 46/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0031 - val_loss: 0.7145\n",
      "Epoch 47/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0029 - val_loss: 0.7006\n",
      "Epoch 48/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0028 - val_loss: 0.6839\n",
      "Epoch 49/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0026 - val_loss: 0.7008\n",
      "Epoch 50/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0026 - val_loss: 0.6864\n",
      "Epoch 51/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0024 - val_loss: 0.6754\n",
      "Epoch 52/100\n",
      "50/50 [==============================] - 0s 946us/step - loss: 0.0024 - val_loss: 0.6899\n",
      "Epoch 53/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0024 - val_loss: 0.6637\n",
      "Epoch 54/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0022 - val_loss: 0.6664\n",
      "Epoch 55/100\n",
      "50/50 [==============================] - 0s 862us/step - loss: 0.0023 - val_loss: 0.6661\n",
      "Epoch 56/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0021 - val_loss: 0.6515\n",
      "Epoch 57/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0020 - val_loss: 0.6346\n",
      "Epoch 58/100\n",
      "50/50 [==============================] - 0s 913us/step - loss: 0.0020 - val_loss: 0.6373\n",
      "Epoch 59/100\n",
      "50/50 [==============================] - 0s 937us/step - loss: 0.0019 - val_loss: 0.6442\n",
      "Epoch 60/100\n",
      "50/50 [==============================] - 0s 931us/step - loss: 0.0018 - val_loss: 0.6325\n",
      "Epoch 61/100\n",
      "50/50 [==============================] - 0s 957us/step - loss: 0.0018 - val_loss: 0.6241\n",
      "Epoch 62/100\n",
      "50/50 [==============================] - 0s 968us/step - loss: 0.0018 - val_loss: 0.6105\n",
      "Epoch 63/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0017 - val_loss: 0.6168\n",
      "Epoch 64/100\n",
      "50/50 [==============================] - 0s 944us/step - loss: 0.0017 - val_loss: 0.6222\n",
      "Epoch 65/100\n",
      "50/50 [==============================] - 0s 934us/step - loss: 0.0016 - val_loss: 0.6176\n",
      "Epoch 66/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0016 - val_loss: 0.6129\n",
      "Epoch 67/100\n",
      "50/50 [==============================] - 0s 930us/step - loss: 0.0015 - val_loss: 0.5915\n",
      "Epoch 68/100\n",
      "50/50 [==============================] - 0s 917us/step - loss: 0.0015 - val_loss: 0.6006\n",
      "Epoch 69/100\n",
      "50/50 [==============================] - 0s 908us/step - loss: 0.0014 - val_loss: 0.5912\n",
      "Epoch 70/100\n",
      "50/50 [==============================] - 0s 990us/step - loss: 0.0014 - val_loss: 0.5981\n",
      "Epoch 71/100\n",
      "50/50 [==============================] - 0s 980us/step - loss: 0.0014 - val_loss: 0.5944\n",
      "Epoch 72/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0014 - val_loss: 0.5867\n",
      "Epoch 73/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0013 - val_loss: 0.5740\n",
      "Epoch 74/100\n",
      "50/50 [==============================] - 0s 962us/step - loss: 0.0013 - val_loss: 0.5755\n",
      "Epoch 75/100\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0013 - val_loss: 0.5755\n",
      "Epoch 76/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0012 - val_loss: 0.5674\n",
      "Epoch 77/100\n",
      "50/50 [==============================] - 0s 846us/step - loss: 0.0012 - val_loss: 0.5701\n",
      "Epoch 78/100\n",
      "50/50 [==============================] - 0s 900us/step - loss: 0.0012 - val_loss: 0.5657\n",
      "Epoch 79/100\n",
      "50/50 [==============================] - 0s 930us/step - loss: 0.0011 - val_loss: 0.5661\n",
      "Epoch 80/100\n",
      "50/50 [==============================] - 0s 906us/step - loss: 0.0011 - val_loss: 0.5600\n",
      "Epoch 81/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0011 - val_loss: 0.5582\n",
      "Epoch 82/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0011 - val_loss: 0.5476\n",
      "Epoch 83/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0011 - val_loss: 0.5522\n",
      "Epoch 84/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0010 - val_loss: 0.5569\n",
      "Epoch 85/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 0.0010 - val_loss: 0.5534\n",
      "Epoch 86/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 9.9959e-04 - val_loss: 0.5383\n",
      "Epoch 87/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 9.7837e-04 - val_loss: 0.5421\n",
      "Epoch 88/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 9.6033e-04 - val_loss: 0.5373\n",
      "Epoch 89/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 9.5100e-04 - val_loss: 0.5317\n",
      "Epoch 90/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.7060e-04 - val_loss: 0.5299\n",
      "Epoch 91/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 9.2609e-04 - val_loss: 0.5346\n",
      "Epoch 92/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.8382e-04 - val_loss: 0.5254\n",
      "Epoch 93/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.7679e-04 - val_loss: 0.5178\n",
      "Epoch 94/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.3923e-04 - val_loss: 0.5225\n",
      "Epoch 95/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.1455e-04 - val_loss: 0.5237\n",
      "Epoch 96/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.0873e-04 - val_loss: 0.5184\n",
      "Epoch 97/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 8.0517e-04 - val_loss: 0.5233\n",
      "Epoch 98/100\n",
      "50/50 [==============================] - 0s 993us/step - loss: 7.8329e-04 - val_loss: 0.5172\n",
      "Epoch 99/100\n",
      "50/50 [==============================] - 0s 1ms/step - loss: 7.5604e-04 - val_loss: 0.5214\n",
      "Epoch 100/100\n",
      "50/50 [==============================] - 0s 974us/step - loss: 7.6083e-04 - val_loss: 0.5108\n",
      "WARNING:tensorflow:11 out of the last 11 calls to <function Model.make_predict_function.<locals>.predict_function at 0x7f9590811440> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args and https://www.tensorflow.org/api_docs/python/tf/function for  more details.\n"
     ]
    }
   ],
   "source": [
    "# build 2-layer MLP network \n",
    "model = Sequential(name='linear_regressor')\n",
    "# 1st layer (input layer) has 64 units (perceptron), input is 1-dim\n",
    "model.add(Dense(units=64, input_dim=1, activation='relu', name='input_layer'))\n",
    "# 2nd layer has 128 unit, output is 1-dim\n",
    "model.add(Dense(units=128, activation='relu', name='hidden_layer'))\n",
    "# 3rd layer (output layer) has 1 unit, output is 1-dim\n",
    "model.add(Dense(units=1, name='output_layer'))\n",
    "# print summary to double check the network\n",
    "model.summary()\n",
    "# indicate the loss function and use stochastic gradient descent\n",
    "# (sgd) as optimizer\n",
    "model.compile(loss='mse', optimizer='sgd')\n",
    "# feed the network with complete dataset (1 epoch) 100 times\n",
    "# batch size of sgd is 4\n",
    "history = model.fit(x_train, y_train, epochs=100, batch_size=4, validation_data=(x_test, y_test))\n",
    "# simple validation by predicting the output based on x\n",
    "y_pred = model.predict(x_test, verbose=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Qualitative Evaluation\n",
    "Let us plot the prediction (green dots) vs test dataset (red stars).\n",
    "We can see that the test data deviates largely when the input is beyond the range of the train data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACx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UDTveYwUz65P0a5Kez7aS7NSyZ2LizOzfJW2v8Nagu//z3DmDKn/9KdWztnqp5Rq0oJp2vEfrMLN3SvqapPvd/fWs68lKJkHt7h9Z7X0zOyjpY5IGvEkHeq91DVpUTTveozWYWYfKIV1y95NZ15OlcF0fZna3pL+S9HF3n866HtTVwo73Znajyjvefz3jmpABMzNJj0oac/eHs64na+GCWtLfS3qXpG+b2Ytm9qWsC6o3M/ukmV2U9GFJ3zSzZ7KuqR7mbiLP73g/JumfWnHHezP7qqT/kPR+M7toZn+UdU0Z2C3pU5LumsuBF83so1kXlRWmkANAcBFb1ACARQhqAAiOoAaA4AhqAAiOoAaA4AhqAAiOoAaA4P4fw+mWdJwxnIUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x_test, y_test, 'r*', x_test, y_pred, 'go', )\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Examine the Train History\n",
    "\n",
    "The `history` variable stores value informationn during training such as value of loss function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['loss', 'val_loss'])\n"
     ]
    }
   ],
   "source": [
    "print(history.history.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAEWCAYAAABsY4yMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deZhcVbnv8e9bQw9JOmM3GQkJSQhkIE1oIDFcMA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BDzqqc1sG7+7vR60Yzeww4mfD8y+xKlUDtnqzvVkR6tkGDBrF48WIAvv3tb9OnTx++/vWvH7COu+PuJBItl3fvvvvunMeZKzkrwZtZ7+gxZ5hZb+DDwNKcHCxVAnVqhiUi7bNq1SomTZrEF7/4RaZOncr69euZNWsWVVVVTJw4ke985ztN65566qksXryYuro6+vfvz+zZs5kyZQrTp09n48aNbR7nzTffZObMmRx//PGcddZZrFu3DoC5c+cyadIkpkyZwsyZMwF49dVXOemkk6isrOT4449n9erVnT7PXJbgBwOPRTcGUsB/u/vTOTlSWglepLu78bfLWP7u9qzuc8KwvtzwsYmHte3y5cu5++67ue222wC4+eabGThwIHV1dcycOZMLLriACRMmHLDNtm3bOP3007n55pv52te+xl133cXs2bNbPcY111zDF77wBS655BLmzJnD9ddfz8MPP8yNN97I/PnzGTx4MFu3bgXgZz/7GV//+te56KKLqKmpIRtP28tZCd7dV7v7lGia6O7/mqtjkSqFWiV4EWm/MWPGcNJJJzV9fuCBB5g6dSpTp05lxYoVLF++/KBtSktLOfvsswE48cQTWbNmTZvHWLBgARdffDEAl19+OX/84x8BmDFjBpdffjl33HEHDQ0NAHzgAx/gpptu4vvf/z5r166lpKSk0+cYj56s6RKoUx28SHd2uCXtXOndu3fT+5UrV/LjH/+Yl156if79+3PppZe22Pu2qKio6X0ymaSuru6wjn377bezYMECnnjiCaZMmcKSJUu47LLLmD59Or/73e8466yzuOeeezjttIPapXRIPNrBp0pUgheRw7Z9+3bKysro27cv69ev55lnnsnKfqdNm8ZDDz0EwP3339+UsFevXs20adP47ne/y4ABA3jnnXdYvXo1Y8eO5brrruPcc89lyZIlnT5+PErwqRLYrc6yInJ4pk6dyoQJE5g0aRJHH300M2bMyMp+b731Vq666ir+7d/+jcGDBze1yPnqV7/Km2++ibvz4Q9/mEmTJnHTTTfxwAMPkE6nGTZsGDfddFOnj2/ZqMjPlqqqKj+sB348eClsWgXX/jX7QYnIYVuxYgXHHXdcvsOIjZb+nma2qLVxvmJSRVO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u18CvABcEK0Wq3MGcPcNwFozGx/N+hCwnBh/14SqmWlm1iv6t954zrH+rjO09t3+Brg8ak0zDdjWWJXTLu7eoyfgHOB14A3gf+c7nhye56mEn2ZLgMXRdA6hTvp5YGX0OjDfsebo/D8IPBG9Pxp4CVgF/Aooznd8OTjfSmBh9H0/DgyI+3cN3Aj8A1gK3AcUx/G7Bh4g3GeoJZTQr2rtuyVU0fw0ym+vEloZtftYGqpARCSmenoVjYiItEIJXkQkppTgRURiSgleRCSmlOBFRGJKCV5iz8zqzWxxxpS1XqFmNipzVECR7iR16FVEerw97l6Z7yBEuppK8FKwzGyNmX3PzF6KprHR/KPM7Plo/O3nzWxkNH+wmT1mZn+Ppg9Eu0qa2e3RWObPmllptP5XzGx5tJ+5eTpNKWBK8FIISptV0VyUsWy7u58M3EoY54bo/b3ufjzwS+CWaP4twIvuPoUwNsyyaP444KfuPhHYCnwqmj8bOCHazxdzdXIirVFPVok9M9vp7n1amL8GOMPdV0cDuW1w90FmtgkY6u610fz17l5uZtXACHevydjHKGCehwc1YGbfBNLufpOZPQ3sJAw18Li778zxqYocQCV4KXTeyvvW1mlJTcb7evbf2zqXMI7IicCijFERRbqEErwUuosyXv8Svf8zYfRKgEuAP0Xvnwe+BE3Pie3b2k7NLAEc6e4vEB5Y0h846FeESC6pRCGFoNTMFmd8ftrdG5tKFpvZAkJh5zPRvK8Ad5nZNwhPVroimn8dMMfMriKU1L9EGBWwJUngfjPrRxgR8EceHrsn0mVUBy8FK6qDr3L3TfmORSQXVEUjIhJTKsGLiMSUSvAiIjGlBC8iElNK8CIiMaUELyISU0rwIiIx9f8BCJQPQaaeRx8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plot history: MSE\n",
    "plt.plot(history.history['loss'], label='Train loss')\n",
    "plt.plot(history.history['val_loss'], label='Test loss')\n",
    "plt.title('MSE')\n",
    "plt.ylabel('MSE value')\n",
    "plt.xlabel('Epochs')\n",
    "plt.legend(loc=\"upper right\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
